﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace VRLauncher
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {

        List<AppItem> list = new List<AppItem>();
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Init(object sender, EventArgs e)
        {
            string configPath = AppDomain.CurrentDomain.BaseDirectory + "Config.xml";
            if (!File.Exists(configPath))
            {
                MessageBox.Show("找不到Config.xml配置文件！无法启动程序！", "启动失败", MessageBoxButton.OK, MessageBoxImage.Error);
                App.Current.Shutdown();
            }

            list = XMLHelper.XMLDeserialize(configPath);

            for(int i = 0; i < list.Count;i++)
            {
                listView.Items.Add(list[i]);
            }
          
        }

        private void StartButton(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;
            string exePath = btn.DataContext.ToString();
            try
            {
                System.Diagnostics.Process.Start(exePath);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
